﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ShareMarking.Systems.Service;
using ShareMarking.Entity;
using ShareMarking.Servcie;

namespace ShareMarking.Web.admin.EnterPrise.setting.TeleText
{
    public partial class Action : ManagePage
    {
        #region 属性=====================================

        /// <summary>
        /// 
        /// </summary>
        protected String Par_T_Name
        {
            get { return txt_T_Name.Text; }
            set { txt_T_Name.Text = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        protected String Par_T_wxTitle
        {
            get { return txt_T_wxTitle.Text; }
            set { txt_T_wxTitle.Text = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        protected String Par_T_wxContent
        {
            get { return txt_T_wxContent.Text; }
            set { txt_T_wxContent.Text = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        protected String Par_T_wxImgUrl
        {
            get { return txt_T_wxImgUrl.Text; }
            set { txt_T_wxImgUrl.Text = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        protected String Par_T_wxUrl
        {
            get { return txt_T_wxUrl.Text; }
            set { txt_T_wxUrl.Text = value; }
        }

        ///// <summary>
        ///// 
        ///// </summary>
        //protected String Par_T_Paramete1
        //{
        //    get { return txt_T_Paramete1.Text; }
        //    set { txt_T_Paramete1.Text = value; }
        //}

        ///// <summary>
        ///// 
        ///// </summary>
        //protected String Par_T_Paramete2
        //{
        //    get { return txt_T_Paramete2.Text; }
        //    set { txt_T_Paramete2.Text = value; }
        //}

        ///// <summary>
        ///// 
        ///// </summary>
        //protected String Par_T_Paramete3
        //{
        //    get { return txt_T_Paramete3.Text; }
        //    set { txt_T_Paramete3.Text = value; }
        //}

        ///// <summary>
        ///// 
        ///// </summary>
        //protected String Par_T_Paramete4
        //{
        //    get { return txt_T_Paramete4.Text; }
        //    set { txt_T_Paramete4.Text = value; }
        //}

        ///// <summary>
        ///// 
        ///// </summary>
        //protected String Par_T_Paramete5
        //{
        //    get { return txt_T_Paramete5.Text; }
        //    set { txt_T_Paramete5.Text = value; }
        //}


        #endregion

        #region 初始化===================================

        protected string action = DTEnums.ActionEnum.Add.ToString(); //操作类型
        private int id = 0;

        protected void Page_Load(object sender, EventArgs e)
        {
            string _action = DTRequest.GetQueryString("action");
            if (!string.IsNullOrEmpty(_action) && _action == DTEnums.ActionEnum.Edit.ToString())
            {
                this.action = DTEnums.ActionEnum.Edit.ToString();//修改类型
                this.id = DTRequest.GetQueryInt("id");
                if (this.id == 0)
                {
                    JscriptMsg("传输参数不正确！", "back", "Error");
                    return;
                }
                if (!qr_wxTeleTextService.Instance.Get_IsExist_ByWhere(qr_wxTeleText._.TypeID == this.id))
                {
                    JscriptMsg("信息不存在或已被删除！", "back", "Error");
                    return;
                }
            }
            if (!Page.IsPostBack)
            {
                //ChkAdminLevel("user_list", ShareMarkingEnums.ActionEnum.View.ToString()); //检查权限

                //绑定下拉框

                if (action == DTEnums.ActionEnum.Edit.ToString()) //修改
                {
                    ShowInfo(this.id);
                }
            }
        }

        #endregion

        #region 绑定下拉框===============================


        #endregion

        #region 赋值操作=================================
        private void ShowInfo(int _id)
        {
            var entity = qr_wxTeleTextService.Instance.Get_SingleEntity_byWhere(qr_wxTeleText._.TypeID == _id);
            if (entity == null) return;
            Par_T_Name = entity.T_Name;
            Par_T_wxTitle = entity.T_wxTitle;
            Par_T_wxContent = entity.T_wxContent;
            Par_T_wxImgUrl = entity.T_wxImgUrl;
            Par_T_wxUrl = entity.T_wxUrl;
            //Par_T_Paramete1 = entity.T_Paramete1;
            //Par_T_Paramete2 = entity.T_Paramete2;
            //Par_T_Paramete3 = entity.T_Paramete3;
            //Par_T_Paramete4 = entity.T_Paramete4;
            //Par_T_Paramete5 = entity.T_Paramete5;
            this.iImagesurl.ImageUrl = entity.T_wxImgUrl;
        }
        #endregion

        #region 增加操作=================================
        private bool DoAdd()
        {
            var entity = new qr_wxTeleText();
            entity.T_Name = Par_T_Name;
            entity.T_wxTitle = Par_T_wxTitle;
            entity.T_wxContent = Par_T_wxContent;
            entity.T_wxImgUrl = Par_T_wxImgUrl;
            entity.T_wxUrl = Par_T_wxUrl;
            //entity.T_Paramete1 = Par_T_Paramete1;
            //entity.T_Paramete2 = Par_T_Paramete2;
            //entity.T_Paramete3 = Par_T_Paramete3;
            //entity.T_Paramete4 = Par_T_Paramete4;
            //entity.T_Paramete5 = Par_T_Paramete5;

            var result = qr_wxTeleTextService.Instance.Add_Entity(entity);

            if (result)
            {
                AddAdminLog(DTEnums.ActionEnum.Add.ToString(), "添加qr_wxTeleText:" + entity.TypeID); //记录日志
            }
            return result;
        }
        #endregion

        #region 修改操作=================================
        private bool DoEdit(int _id)
        {
            var entity = qr_wxTeleTextService.Instance.Get_SingleEntity_byWhere(qr_wxTeleText._.TypeID == _id);
            if (entity == null) return false;
            entity.T_Name = Par_T_Name;
            entity.T_wxTitle = Par_T_wxTitle;
            entity.T_wxContent = Par_T_wxContent;
            entity.T_wxImgUrl = Par_T_wxImgUrl;
            entity.T_wxUrl = Par_T_wxUrl;
            //entity.T_Paramete1 = Par_T_Paramete1;
            //entity.T_Paramete2 = Par_T_Paramete2;
            //entity.T_Paramete3 = Par_T_Paramete3;
            //entity.T_Paramete4 = Par_T_Paramete4;
            //entity.T_Paramete5 = Par_T_Paramete5;

            var result = qr_wxTeleTextService.Instance.Update_Entity(entity);

            if (result)
            {
                AddAdminLog(DTEnums.ActionEnum.Edit.ToString(), "修改qr_wxTeleText:" + entity.TypeID); //记录日志
            }
            return result;
        }
        #endregion

        #region 保存按钮事件=============================

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (action == DTEnums.ActionEnum.Edit.ToString())
            { //修改
                //ChkAdminLevel("user_list", ShareMarkingEnums.ActionEnum.Edit.ToString()); //检查权限
                if (!DoEdit(this.id))
                {
                    JscriptMsg("保存过程中发生错误！", "", "Error");
                    return;
                }
                JscriptMsg("修改成功！", "Index.aspx", "Success");
            }
            else //添加
            {
                //ChkAdminLevel("user_list", ShareMarkingEnums.ActionEnum.Add.ToString()); //检查权限
                if (!DoAdd())
                {
                    JscriptMsg("保存过程中发生错误！", "", "Error");
                    return;
                }
                JscriptMsg("添加成功！", "Index.aspx", "Success");
            }
        }

        #endregion
    }

}